package com.hengda.smart.speak.d;

import android.app.Application;

import com.hengda.platform.easyhttp.HttpManager;
import com.hengda.platform.easyhttp.strategy.CacheStrategy;
import com.hengda.smart.speak.d.config.Constant;
import com.hengda.smart.speak.d.response.ApiListTest;
import com.hengda.smart.speak.d.response.ApiTest;

import java.io.File;
import java.io.IOException;
import java.security.InvalidParameterException;

import android_serialport_api.SerialPort;

/**
 * author: cwd
 * created on: 2017/6/5 17:19
 * email:xyzcwd02@163.com
 * description:
 */
public    class App  extends Application {
    private static App instance;
    public static synchronized App getInstance() {
        return instance;
    }
    private static SerialPort mSerialPort = null;


    public static int screenW;
    public static int screenH;


    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        HttpManager.init(this,
                Constant.BASE_URL,
                Constant.SUCCESS_CODE,
                new ApiTest(),
                new ApiListTest(),
                CacheStrategy.cacheAndRemote());
    }

    public SerialPort getSerialPort() throws SecurityException, IOException,
            InvalidParameterException {
        if (mSerialPort == null) {
            String path = "/dev/s3c2410_serial3";
            int baudrate = 57600;
			/* Check parameters */
            if ((path.length() == 0) || (baudrate == -1)) {
                throw new InvalidParameterException();
            }
			/* Open the serial port */
            mSerialPort = new SerialPort(new File(path), baudrate, 0);
        }
        return mSerialPort;
    }

    //==========================================launcher command===================================================================
    //打开音频模块
    public static final String ACTION_OPEN_AUDIO  = "HENGDA_OPEN_AUDIO";
    //关闭音频模块
    public static final String ACTION_CLOSE_AUDIO = "HENGDA_CLOSE_AUDIO";
    //设置
    public static final String ACTION_SET_AUDIO   = "HENGDA_SET_AUDIO";
    //通道占用
    public static final String ACTION_OPEN_CHANNEL ="HENGDA_OPEN_CHANNEL";
    //通道释放
    public static final String ACTION_CLOSE_CHANNEL ="HENGDA_CLOSE_CHANNEL";
    //控制器关闭哦
    public static final String ACTION_CLOSE_CONTROL ="HENGDA_CLOSE_CONTROL";
    //800M音频模块打开成功
    public static final String BROADCAST_AUDIO_SUCCESS="HENDDA_OPEN_AUDIO_SUCCESS";
    //800M音频模块打开失败
    public static final String BROADCAST_AUDIO_FAILURE="HENDDA_OPEN_AUDIO_FAIL";
    //红外适配
    public static final String BROADCAST_INFRARED_CHANNEL ="HENDDA_AUTO_IR";
    //首次冲突
    public static final String BROADCAST_ERROR_FIRST   ="HENDDA_CHANNEL_ERROR_FIRST";
    //中途冲突
    public static final String BROADCAST_ERROR_HALFWAY  ="HENDDA_CHANNEL_ERROR_HALFWAY";

    public static final String FIELD_VOLUME    = "DEVICE_VOLUME";
    public static final String FIELD_CHANNEL   = "DEVICE_CHANNEL";
    public static final String FIELD_CHANNEL_0 = "DEVICE_CHANNEL800_0";
    public static  final String FIELD_ERROR_CHANNEL="DEVICE_CHANNEL_ERROR";

    //==============================================================================================================
    public static boolean TEST_DEBUG = false;

    public void closeSerialPort() {
        if (mSerialPort != null) {
            mSerialPort.close();
            mSerialPort = null;
        }
    }

}
